package com.bilibili.bilibili.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bilibili.bilibili.R;
import com.bilibili.bilibili.model.RecommendModel;
import com.bilibili.bilibili.utils.GlideImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称：bilibili
 * 类描述：
 * 创建人：${丁江楠}
 * 创建时间：2017/3/10 14:26
 * 修改人：${丁江楠}
 * 修改时间：2017/3/10 14:26
 * 修改备注：
 */
public class RecommendAdapter extends BaseAdapter {
    private Context context;
    private List<RecommendModel.DataBean> list=new ArrayList<>();

    public RecommendAdapter(Context context, List<RecommendModel.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder=null;
        if(view==null){
            view=View.inflate(context, R.layout.item_recommend,null);
            viewHolder=new ViewHolder();
            viewHolder.imageView= (ImageView) view.findViewById(R.id.recommend_imageView);
            viewHolder.text_play= (TextView) view.findViewById(R.id.text_play);
            viewHolder.text_title= (TextView) view.findViewById(R.id.text_title);
            viewHolder.text_tname= (TextView) view.findViewById(R.id.text_tname);
            view.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) view.getTag();
        }
        RecommendModel.DataBean dataBean = list.get(i);
        GlideImageLoader imageLoader=new GlideImageLoader();
        imageLoader.displayImage(context,dataBean.getCover(),viewHolder.imageView);
      //  viewHolder.text_danmu.setText(dataBean.getDanmaku()+"");
        viewHolder.text_title.setText(dataBean.getTitle());
        viewHolder.text_play.setText(dataBean.getPlay()+"");
       // viewHolder.text_time.setText(dataBean.getDuration()+"");
        viewHolder.text_tname.setText(dataBean.getTname());
        return view;
    }
    class ViewHolder{
        ImageView imageView;
        TextView text_play;
        TextView text_time;
        TextView text_danmu;
        TextView text_title;
        TextView text_tname;
    }
}
